interface State {
	searchList: string[]
}

const initState: State = {
	searchList: JSON.parse(localStorage.getItem('searchList') || '[]')
}

const CLEAR_SEARCH_LIST = 'CLEAR_SEARCH_LIST'


export function clearSearchListActionCreate() {
	return { type: CLEAR_SEARCH_LIST }
}

interface ClearSearchListType {
	type: typeof CLEAR_SEARCH_LIST
}


type ActionType = ClearSearchListType


const searchReducer = (state =  initState, action: ActionType) => {
	switch(action.type) {
		case CLEAR_SEARCH_LIST:
			localStorage.removeItem('searchList')
			return {
				searchList: []
			}
		default: 
			return state
	}
}

export default searchReducer